package com.duniptech.soa.service;

import com.duniptech.soa.stub.rtsimulation.RTSimulationStub;




public class RTSimulationService implements RTSimulationServiceInterface {
	
	protected RTSimulationStub service;
	protected String endPoint;
		
	public RTSimulationService(String endPoint) throws Exception {
		this.endPoint = endPoint;
		service = new RTSimulationStub(endPoint);
	}
	
	public void receive(String key, String simulatorFrom, String portFrom, String simulatorTo, String portTo, String[] xmlValues) throws Exception {
		RTSimulationStub.Receive args = new RTSimulationStub.Receive();
		args.setKey(key);
		args.setSimulatorFrom(simulatorFrom);
		args.setPortFrom(portFrom);
		args.setSimulatorTo(simulatorTo);
		args.setPortTo(portTo);
		args.setXmlValues(xmlValues);
		
		service.receive(args);
	}
	
	public void newSimulator(String xmlAtomicAsString) throws Exception {
		RTSimulationStub.NewSimulator args = new RTSimulationStub.NewSimulator();
		args.setXmlAtomicAsString(xmlAtomicAsString);
		
		service.newSimulator(args);
	}
	
	public void addConnection(String key, String simulatorFrom, String portFrom, String simulatorTo, String endPointServiceTo, String portTo) throws Exception {
		RTSimulationStub.AddConnection args = new RTSimulationStub.AddConnection();
		args.setKey(key);
		args.setSimulatorFrom(simulatorFrom);
		args.setPortFrom(portFrom);
		args.setSimulatorTo(simulatorTo);
		args.setEndPointServiceTo(endPointServiceTo);
		args.setPortTo(portTo);
		
		service.addConnection(args);
	}
	
	public String getEndPoint() {
		return endPoint;
	}

	public void initialize(String key) throws Exception {
		RTSimulationStub.Initialize args = new RTSimulationStub.Initialize();
		args.setKey(key);

		service.initialize(args);
	}

	public void simulate(String key) throws Exception {
		RTSimulationStub.Simulate args = new RTSimulationStub.Simulate();
		args.setKey(key);
		
		service.simulate(args);
	}
	
	public String getConsole(String clientIp) throws Exception {
		RTSimulationStub.GetConsole args = new RTSimulationStub.GetConsole();
		args.setClientIp(clientIp);
		
		RTSimulationStub.GetConsoleResponse response = service.getConsole(args);
		return response.get_return();
	}
	
	public void exit(String key) throws Exception {
		RTSimulationStub.Exit args = new RTSimulationStub.Exit();
		args.setKey(key);
		
		service.exit(args);
	}
	
	public String observe(String clientIp, String serverPackage, String xmlModelAsString, double observeSeconds) throws Exception {
		RTSimulationStub.Observe args = new RTSimulationStub.Observe();
		args.setClientIp(clientIp);
		args.setServerPackage(serverPackage);
		args.setXmlModelAsString(xmlModelAsString);
		args.setObserveSeconds(observeSeconds);
		
		RTSimulationStub.ObserveResponse response = service.observe(args);
		return response.get_return();
	}

}
